package com.espirit.eap.sa;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.espirit.eap.pagelayout.ModelService;
@Service
public class PrivilegeManager {
	
	@Resource
	private ModelService modelService;
	
	private List<Privilege> getRecordLimitPrivileges(List<Privilege> selectedPrivileges){
		List<Privilege> results = new ArrayList<Privilege>();
		List<Privilege> all = getAllPrivilege();
		for(Privilege privilege : all){
			if (privilege.getModelSimpleName() != null && privilege.getScopeType() != null){
				results.add(privilege);
			}
		}
		return results;
	}
	
	private List<Privilege> getFieldLimitPrivileges(List<Privilege> selectedPrivileges){
		List<Privilege> results = new ArrayList<Privilege>();
		List<Privilege> all = getAllPrivilege();
		for(Privilege privilege : all){
			if (privilege.getModelSimpleName() != null && privilege.getScopeType() == null){
				results.add(privilege);
			}
		}
		return results;
	}
	
	private List<Privilege> getExcludePrivileges(List<Privilege> selectedPrivileges){
		List<Privilege> results = new ArrayList<Privilege>();
		List<Privilege> all = getAllPrivilege();
		for(Privilege privilege : all){
			if (privilege.getModelSimpleName() == null){
				results.add(privilege);
			}
		}
		return results;
	}
	
	private List<Privilege> getAllPrivilege() {
		List<Privilege> allPrivilege = (List<Privilege>) modelService
				.searchModelList(Privilege.class.getName(), null, null, null, "", "", false,
						0, 0, false, null, null).getData();
		
		return allPrivilege;
//		return (List<Privilege>) CollectionUtils.subtract(allPrivilege,
//				selectedPrivileges);
	}
}
